package EX1;
class Draw {
    private int height;//属性
    //输入高度
    public void getHeight(int height) {
        this.height = height;
    }
    // 绘制三角形
    public void drawTriangle() {
        for (int i = 1; i <= height; i++) {
            for (int j = 0; j < i; j++) {
                System.out.print("*");//确保*输出在同一行
            }
            System.out.println();
        }
    }
    // 绘制矩形
    public void drawRectangle() {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < height; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
    // 绘制正方形
    public void drawSquare() {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < height; j++) {
                System.out.print("*  ");
            }
            System.out.println();
        }
    }
    // 绘制平行四边形
    public void drawParallelogram() {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < i; j++) {
                System.out.print(" ");
            }
            for (int k = 0; k < height; k++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}
public class Exercise4 {
    public static void main(String[] args) {
        // 创建Draw类对象并指定高度为5
        Draw figure = new Draw();
        figure.getHeight(5);
        System.out.println("三角形：");
        figure.drawTriangle();
        System.out.println("矩形：");
        figure.drawRectangle();
        System.out.println("正方形：");
        figure.drawSquare();
        System.out.println("平行四边形：");
        figure.drawParallelogram();
    }
}
